using System;
//using System.Xml.Linq;
//using System.Linq;
using System.Security.Cryptography;
using System.Text;



	public class clsEncriptacion
	{
		
		
		#region Constructor
		public clsEncriptacion()
		{
		}
		#endregion
		
		//¡¡¡ IMPORTANTE !!!! Consultar formulario frmLogin y frmUsuarios para ejemplos ecriptacion y desencriptacion
		
		#region EncriptarCadena
		public static string EncriptarCadena(string prmOriginal, string prmClave)
		{
			TripleDESCryptoServiceProvider des;
			MD5CryptoServiceProvider hashmd5;
			byte[] keyhash;
			byte[] buff;
			hashmd5 = new MD5CryptoServiceProvider();
			keyhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(prmClave));
			hashmd5 = null;
			des = new TripleDESCryptoServiceProvider();
			des.Key = keyhash;
			des.Mode = CipherMode.ECB;
			buff = ASCIIEncoding.ASCII.GetBytes(prmOriginal);
			return Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(buff, 0, buff.Length));
		}
		#endregion
		
		#region DesencriptarCadena
		public static string DesencriptarCadena(string prmEncriptada, string prmClave)
		{
			TripleDESCryptoServiceProvider des;
			MD5CryptoServiceProvider hashmd5;
			byte[] keyhash;
			byte[] buff;
			hashmd5 = new MD5CryptoServiceProvider();
			keyhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(prmClave));
			hashmd5 = null;
			des = new TripleDESCryptoServiceProvider();
			des.Key = keyhash;
			des.Mode = CipherMode.ECB;
			buff = Convert.FromBase64String(prmEncriptada);
			return ASCIIEncoding.ASCII.GetString(des.CreateDecryptor().TransformFinalBlock(buff, 0, buff.Length));
		}
		#endregion
		
	}

